/*
import java.awt.Point;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

public class TraceFileToXML {
	public static FileOutputStream fout;
	public static OutputStreamWriter out;
	public static String sCurrentLine;
	public static ArrayList<Point> Node;
	public static HashMap<String,String> packetSourceID;
	public static HashMap<String,Integer> packetDestID;
	
		public static void main(String[] args) throws IOException{
		    fout = new FileOutputStream("TextToXML.xml");
			out = new OutputStreamWriter(fout);
			out.write("<?xml version=\"1.0\"?>\r\n");  
		    out.write("<trace>\r\n\r\n");  
		    
		    Node=new ArrayList<Point>();
		    packetSourceID=new HashMap<String,String>();
		    packetDestID=new HashMap<String,Integer>();
		    InitNode();
			CreateNodeElements();
			CreatePacketElements();
			CreateEventElements();
			
			out.write("</trace>");
			out.close();
			
			System.out.println("Finish");
		}
		
		
		public  static BufferedReader ReadFile(String path) throws FileNotFoundException{
			BufferedReader br = new BufferedReader(new FileReader(path));
			return br;
		}

		public static void InitNode() throws IOException{
			BufferedReader br=ReadFile("topo_data.tcl");
			String line1,retval1[];
			String line2,retval2[];
			String line3,retval3[];
			while ((line1 = br.readLine()) != null && (line2 = br.readLine()) != null && (line3 = br.readLine()) != null){
				retval1=line1.split(" ");
				retval2=line2.split(" ");
				retval3=line3.split(" ");
				Node.add(new Point(Integer.parseInt(retval1[3]),Integer.parseInt(retval2[3])));
				
			}
		}
		
		public static int FindDestId(int packetId) throws IOException{
			BufferedReader br=ReadFile("trace.tr");
			String retval[] = null;
			int countDestId=0;
			while ((sCurrentLine = br.readLine()) != null){
				retval = sCurrentLine.split(" ");
				if(retval[0].equals("r") && Integer.parseInt(retval[6])==packetId){
					countDestId++;
					if(countDestId>=2) break;
				} 					
			}
			if(countDestId>=2 || countDestId==0 ) return -1;
			else return Integer.parseInt(retval[2].substring(1, retval[2].length()-1));
		}
	 	
		public static void CreateEventElements() throws IOException {
			BufferedReader br=ReadFile("trace.tr");
			String retval[];
			String sourcePort;
			String destPort;
			int destID=0;
			
			out.write("  <event>\r\n"); 
			 while ((sCurrentLine = br.readLine()) != null){ 
			    retval = sCurrentLine.split(" ");
			    if(!retval[0].equals("N") && !retval[0].equals("M") && !retval[0].equals("D")){
				    destID=packetDestID.get(retval[6]);
					if(destID==-1){
						sourcePort="255";
						destPort="-1";
					}
					else {
						sourcePort="0";
						destPort="0";
					}
					if(retval[0].equals("r")){
						out.write("    <event type='recevie' time='"+retval[1]+"' packet-id='"+retval[6]+"' " +
								       "source-id='"+packetSourceID.get(retval[6])+"' source-port='"+sourcePort+"' dest-id='"+retval[2].substring(1, retval[2].length()-1)+"' " +
									   "dest-port='"+destPort+"' remain-energy='"+retval[14]+"'></event>"+"\r\n");
					}
					if(retval[0].equals("s")){
						out.write("    <event type='send' time='"+retval[1]+"' packet-id='"+retval[6]+"' " +
								       "source-id='"+retval[2].substring(1, retval[2].length()-1)+"' source-port='"+sourcePort+"' dest-id='"+destID+"' " +
									   "dest-port='"+destPort+"' remain-energy='"+retval[14]+"'></event>"+"\r\n");
					}
					if(retval[0].equals("f")){
						out.write("    <event type='forward' time='"+retval[1]+"' packet-id='"+retval[6]+"' " +
								       "source-id='"+packetSourceID.get(retval[6])+"' source-port='"+sourcePort+"' dest-id='"+retval[2].substring(1, retval[2].length()-1)+"' " +
									   "dest-port='"+destPort+"' remain-energy='"+retval[14]+"'></event>"+"\r\n");
					}
			    }
			 }
			 out.write("  </event>\r\n\r\n"); 	
		}

		public static void CreatePacketElements() throws IOException {
			BufferedReader br=ReadFile("trace.tr");
			String retval[];
			String sourcePort;
			String destPort;
			int destID=0;
			
			out.write("  <packet>\r\n"); 
			 while ((sCurrentLine = br.readLine()) != null){ 
				retval= sCurrentLine.split(" ");
				if(retval[0].equals("s")){
					destID=FindDestId(Integer.parseInt(retval[6]));
					if(destID==-1){
						sourcePort="255";
						destPort="-1";
					}
					else {
						sourcePort="0";
						destPort="0";
					}
					out.write("    <packet id='"+retval[6]+"' type='"+retval[7]+"' " +
							"source-id='"+retval[2].substring(1, retval[2].length()-1)+"' source-port='"+sourcePort+"' dest-id='"+destID+"' " +
									"dest-port='"+destPort+"' size='"+retval[8]+"'></packet>"+"\r\n");
					packetSourceID.put(retval[6],retval[2].substring(1, retval[2].length()-1));
					packetDestID.put(retval[6], destID);
				}
			 }
			 out.write("  </packet>\r\n\r\n"); 
		}

		public static void CreateNodeElements() throws IOException {
			BufferedReader br=ReadFile("trace.tr");
			String retval[];
			 out.write("  <node>\r\n"); 
			 while ((sCurrentLine = br.readLine()) != null){ 
			    retval = sCurrentLine.split(" ");
				if(retval[0].equals("N")){
					out.write("    <node id='"+retval[4]+"' time='"+retval[2]+"' x='"+Node.get(Integer.parseInt(retval[4])).x+"' y='"+Node.get(Integer.parseInt(retval[4])).y+"' energy='"+retval[6]+"'></node>"+"\r\n");
				}
			 }
			 out.write("  </node>\r\n\r\n"); 	
		}
		
		

}
*/